package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.NoticeMapper;
import com.gxa.zhonglong.pojo.Notice;
import com.gxa.zhonglong.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    private NoticeMapper noticeMapper;
    @Override
    public void insert(Notice notice) throws BusinessException {
        Notice notice1 = noticeMapper.selectById(notice.getNoticeId());
        if(notice1!=null){
            throw new BusinessException(ExceptionCode.DUPLICATE_ROlE_NAME);
        }else{
            noticeMapper.insert(notice);
        }
    }

    @Override
    public void update(Notice notice) {
        noticeMapper.update(notice);
    }

    @Override
    public void delete(Long noticeId) throws BusinessException {
        Notice notice = noticeMapper.selectById(noticeId);
        if(notice==null){
            throw new BusinessException(ExceptionCode.DELETE_DEFEATED);
        }else{
            noticeMapper.delete(noticeId);
        }
    }

    @Override
    public List<Notice> selectSend(Boolean inUse, Integer page, Integer size) {
        Integer PAGE=(page-1)*size;
        return noticeMapper.selectSend( inUse,PAGE,size);
    }

    @Override
    public Notice selectById(Long noticeId) {

        return noticeMapper.selectById(noticeId);
    }
}
